﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Definition;
using Besture.Common.Helper;
using Besture.Model;

namespace Besture.UI.Portal.FindUserPwd
{
    public partial class FindUserPwdList1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSendClick(object sender, EventArgs e)
        {
            if (Session["CheckCode"] != null && txtVerificationCode.Text.ToLower() != Session["CheckCode"].ToString().ToLower())
            {
                FunHelper.Alert(Page, "验证码错误！");
                return;
            }
            UserBaseDac userBaseDac = new UserBaseDac();
            UserBaseModel userBaseModel = userBaseDac.GetDataByUser(txtPhone.Text);
            if (userBaseModel == null)
            {
                FunHelper.Alert(Page, "手机号码错误！");
                return;
            }
           if(PhoneSendSmsSend()>0)//发送短信
                Response.Redirect("FindUserPwdList2.aspx?user=" + EncryptHelper.Encrypt(userBaseModel.ID.ToString()));

        }

        public int PhoneSendSmsSend()
        {
            try
            {

                string code = (new Random().Next(000000, 999999)).ToString();
                Session["registerPhoneCode"] = code;
                new SendSms().SendMsg(AppSettings.SmsName, txtPhone.Text, AppSettings.SmsSignature + code, "5");
                return 1;
            }
            catch (Exception)
            {
                return 0;
            }
            return 0;
        }
    }
}